package com.woniu.util;


import java.io.Serializable;

public class CommentResult<T> implements Serializable {

    //状态码

    private Long code;
    //提示消息

    private String message;
    //响应数据

    private T data;

    public CommentResult()
    {
    }

    public CommentResult(T data)
    {
        this.data = data;
    }

    public CommentResult(Long code, T data)
    {
        this.code = code;
        this.data = data;
    }

    public CommentResult(String message, T data)
    {
        this.message = message;
        this.data = data;
    }

    public CommentResult(Long code, String message)
    {
        this.code = code;
        this.message = message;
    }

    public CommentResult(Long code, String message, T data)
    {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 响应成功的结果
     *
     * @return 状态码 200
     */
    public static CommentResult success()
    {
        return new CommentResult(ResultUtil.SUCCESS.getCode(), ResultUtil.SUCCESS.getMessage());
    }

    public static CommentResult success(String message)
    {
        return new CommentResult(ResultUtil.SUCCESS.getCode(), message);
    }

    public static <T> CommentResult success(T data)
    {
        return new CommentResult(ResultUtil.SUCCESS.getCode(), ResultUtil.SUCCESS.getMessage(), data);
    }

    public static <T> CommentResult success(String message, T data)
    {
        return new CommentResult(ResultUtil.SUCCESS.getCode(), message, data);
    }

    /**
     * 响应失败
     *
     * @return 状态码500
     */
    public static CommentResult failed()
    {
        return new CommentResult(ResultUtil.FAILED.getCode(), ResultUtil.FAILED.getMessage());
    }

    public static CommentResult failed(String message)
    {
        return new CommentResult(ResultUtil.FAILED.getCode(), message);
    }

    /**
     * 参数验证失败
     *
     * @return 状态码 400
     */
    public static CommentResult valetateFailed()
    {
        return new CommentResult(ResultUtil.VALIDATE_FAILED.getCode(), ResultUtil.VALIDATE_FAILED.getMessage());
    }

    public static CommentResult valetateFailed(String msg)
    {
        return new CommentResult(ResultUtil.VALIDATE_FAILED.getCode(), msg);
    }

    /**
     * 未认证
     *
     * @return 状态码401
     */
    public static CommentResult unathorizedFailed()
    {
        return new CommentResult(ResultUtil.UNAUTORIED.getCode(), ResultUtil.UNAUTORIED.getMessage());
    }

    /**
     * 未授权
     *
     * @return 状态码403
     */
    public static CommentResult forbiddenFailed()
    {
        return new CommentResult(ResultUtil.FORBIDDEN.getCode(), ResultUtil.FORBIDDEN.getMessage());
    }

    public Long getCode()
    {
        return code;
    }

    public void setCode(Long code)
    {
        this.code = code;
    }

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public T getData()
    {
        return data;
    }

    public void setData(T data)
    {
        this.data = data;
    }
}
